﻿@using RuoVea.ExConfig
@using RuoVea.Gantt.Entity
@{
    var host = Appsettings.app("BaseFile:HostUrl");
    GanttTtasks data = ViewBag.data;
    List<GanttItem> types = ViewBag.type; if (types == null) types = new List<GanttItem>();
    List<GanttStart> Starts = ViewBag.Start; if (Starts == null) Starts = new List<GanttStart>();
    List<GanttPriority> Prioritys = ViewBag.Priority; if (Prioritys == null) Prioritys = new List<GanttPriority>();
    Layout = "";
}
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>信息</title>
    <!--引入css和js-->
    <link rel="stylesheet" href="@host/res/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="@host/css/index.css" media="all">
    <script src="@host/res/layui/layui.js"></script>
</head>
<body>
    <div style="margin:10px;">
        <form class="layui-form">
            <input type="hidden" name="id" id="id" value="@ViewBag.id">
            <div class="layui-form-item">
                <label class="layui-form-label">名称:</label>
                <div class="layui-input-block">
                    <input type="text" name="label" id="label" required lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input" lay-verType="tips" value="@data.label">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">开始时间:</label>
                <div class="layui-input-block">
                    <input type="text" name="start" id="start" required lay-verify="required" placeholder="开始时间" autocomplete="off" class="layui-input" lay-verType="tips" value="@data.start.ToString("yyyy-MM-dd")">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">结束时间:</label>
                <div class="layui-input-block">
                    <input type="text" name="end" id="end" required lay-verify="required" placeholder="结束时间" autocomplete="off" class="layui-input" lay-verType="tips" value="@data.end.ToString("yyyy-MM-dd")">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">进度:</label>
                <div class="layui-input-block">
                    <div id="percent" style="padding:18px 0;"></div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">类别:</label>
                <div class="layui-input-block">
                    <select name="ItemId" id="ItemId" lay-verify="required" lay-verType="tips">
                        @foreach (var item in types)
                        {
                            <option value="@item.Id">@item.Name</option>
                        }
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">状态:</label>
                <div class="layui-input-block">
                    <select name="StartId" id="StartId" lay-verify="required" lay-verType="tips">
                        @foreach (var item in Starts)
                        {
                            <option value="@item.Id">@item.Name</option>
                        }
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">优先级:</label>
                <div class="layui-input-block">
                    <select name="PriorityId" id="PriorityId" lay-verify="required" lay-verType="tips">
                        @foreach (var item in Prioritys)
                        {
                            <option value="@item.Id">@item.Name</option>
                        }
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">紧前任务:</label>
                <div class="layui-input-block">
                    <input type="text" name="dependentOn" placeholder="紧前任务" autocomplete="off" class="layui-input" value="@data.dependentOn">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">上级任务:</label>
                <div class="layui-input-block">
                    <input type="text" name="parentId" placeholder="上级任务" autocomplete="off" class="layui-input" value="@data.parentId">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">用户:</label>
                <div class="layui-input-block">
                    <input type="text" name="user" placeholder="用户" autocomplete="off" class="layui-input" value="@data.user">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-filter="formDemo" lay-submit>提交</button>
                </div>
            </div>
        </form>
    </div>

    <script type="text/javascript">
        layui.use(['slider','form',"laydate","jquery"], function () {
            var form = layui.form,laydate=layui.laydate,slider = layui.slider,$=layui.jquery;
            var  percent= @(data.percent??0);
             laydate.render({ elem: '#start'  });
             laydate.render({ elem: '#end'  });
             slider.render({ elem: '#percent',value: @(data.percent??0)  ,

             change: function(value){ percent=value; }  });

             $("select[name='ItemId']").val('@(data.ItemId??1)');
             $("select[name='StartId']").val('@(data.StartId??1)');
             $("select[name='PriorityId']").val('@(data.PriorityId??1)');

             form.render();

            form.verify({
                title: function (value, item) {
                    if (value.length < 5) {
                        return '标题至少得5个字符啊';
                    }
                }, fname: function (value) {
                    if (value.length < 4) {
                        return '请输入至少4位的用户名';
                    }
                }, contact: function (value) {
                    if (value.length < 4) {
                        return '内容请输入至少4个字符';
                    }
                }
                , phone: [/^1[3|4|5|7|8]\d{9}$/, '手机必须11位，只能是数字！']
                , email: [/^[a-z0-9._%-]+@@([a-z0-9-]+\.)+[a-z]{2,4}$|^1[3|4|5|7|8]\d{9}$/, '邮箱格式不对']
            });
            //监听提交
            form.on('submit(formDemo)', function(data){
                //ajax
                //console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
                //console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
                //console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value};获取单个值data.field["title"]

                 data.field.percent=percent;
                 var  obj=  data.field;
                $.post("@host/Task/TasksView",obj,function(res){
                    var data=JSON.parse(res)
                    if(data.code==1){
                        layer.alert(data.msg,{icon:1},function(res){
                            var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                        parent.layer.close(index);
                        });
                    }else{
                        layer.msg(data.msg,{icon:2});
                    }
                });
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });
        });
    </script>
</body>
</html>

